/*******
Edits: Bogdan Mukhametkaliev
Original: Jared Stolove (see Archive/Code/12. Table version main results)
using new panel, using correct specification for cluster FE, and restructuring 
the tables
Purpose: Table summarizing treatment effects on PM
Date edited: 09.21.21
*******/

*** CEMS: 
use "$CEMS_DATA_IN/CEMS Panel Monthly (clean, PO).dta", clear
	keep if !mi(treat) //phases II and IV only 
	drop if (treat == 0) & (month > PO_month)
	drop if (event_time < -24) | (event_time > 48)
	gen treat_post = treat * post 
	label var treat_post "Treatment Effect"
	eststo clear
	gen log_pm = log(avg_pm)
	label var log_pm "Log(PM)"
	label var avg_pm "PM, mg/Nm3"
	
foreach outcome in avg_pm log_pm{
    eststo CEMS_`outcome'_plant:   reghdfe `outcome' treat_post, absorb(uniqid month) vce(cluster uniqid)
		estadd local monthyearFE "Yes"
		estadd local unitFE      "Yes"
		estadd scalar R2 e(r2)
		estadd ysumm
}

esttab `tablist' using "$EMISSIONS_TABS/Table_C3.tex", ///
				 se star(* 0.10 "**" 0.05 "***" 0.01) label title("Effects of Treatment on PM") replace ///
				 drop( _cons ) prehead("\begin{tabular}{l*{2}{c}}\toprule") posthead("&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}\\ \hline \addlinespace") nonumbers ///
				 prefoot("\addlinespace") postfoot("\bottomrule \end{tabular}") ///
				 scalars("monthyearFE Year-Month FE"   "unitFE Plant fixed effects"  "N_clust Plants" "R2 \$R^2$" "ymean Mean dependent variable") ///
				 sfmt(%3s %3s %8.0g %9.4f %9.3f)
